package ExceptionTest.Test1_1;

import java.io.IOException;

public class Main {
    public static void main(String[] args) throws Exception {
//        test1();
//        System.out.println("最终返回结果： "+test2());
//        test3();
//        test4();
        try {int result = test6(10, 0);}catch (Exception e){
            System.out.println("main 函数异常");
        }


    }

    public static int test6(int num1, int num2) throws Exception
    {
        try {
             int result = num1/num2;
             return result;
        }catch (Exception e){
            throw new Exception("参数异常");
        }


    }
    public static void test1()
    {
        try {
            Student student = new Student();
            student.setAge(-1);
        }catch (NullPointerException e){
            System.out.println("出异常了 NullPointerException");
        }catch (IllegalArgumentException e){
            System.out.println("出异常了 IllegalArgumentException");
        }
        
        
    }
    public static int test2()
            // 最终返回结果为 1，
    {
        try {
            Student student = new Student();
            student.setAge(-1);
            return 0;
        }catch (Exception e){
            System.out.println("catch 块 出异常了 Exception");
        }finally {
            System.out.println("finally块 肯定会被执行的代码");
            return 1;
        }
    }
    public static void test3()
    {
        try {
            Student student = new Student();
            student.setAge(-1);
            student.setName("");
        } finally {
            System.out.println("test3的finally块 肯定会被执行的代码");
        }
    }

    public static void test4()throws IOException, RuntimeException
    {
        Student student = new Student();
        student.setAge(55);
        throw new IOException("抛出IOException");

    }

}
